package cn.wolfcode.controller;

import cn.wolfcode.domain.Dept;
import cn.wolfcode.domain.Emp;
import cn.wolfcode.domain.Result;
import cn.wolfcode.service.DeptService;
import cn.wolfcode.service.impl.DeptServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptServiceImpl deptService;
    @GetMapping
    public Result getAll()
    {
        List<Dept> depts=deptService.getAll();
        return Result.success(depts);
    }
    @DeleteMapping("/{id}")
    public  Result delete(@PathVariable("id")Long id)
    {
       deptService.delete(id);
       return  Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Dept dept)
    {
        deptService.add(dept);
        return  Result.success();
    }
    @PutMapping()
   public  Result update(@RequestBody Dept dept)
    {
        deptService.update(dept);
        return  Result.success();
    }
    @GetMapping("/{id}")
    public  Result selectOneById(@PathVariable("id")Long id)
    {
        Dept dept=deptService.selectOneById(id);
        return Result.success(dept);
    }
}
